import multiprocessing
import os
import time

from loguru import logger


# 编写代码
def coding(num):
    logger.debug('coding.pid: %d, ppid: %d' % (os.getpid(), os.getppid()))
    for _ in range(num):
        logger.info('coding...')
        time.sleep(1)


# 听音乐
def music(count):
    logger.debug('music.pid: %d, ppid: %d' % (os.getpid(), os.getppid()))
    for _ in range(count):
        logger.info('music...')
        time.sleep(1)


if __name__ == '__main__':
    # 主进程
    logger.debug('main process: %d' % os.getpid())

    # 创建子进程并指定执行的任务
    coding_process = multiprocessing.Process(target=coding, args=(3,))
    music_process = multiprocessing.Process(target=music, kwargs={'count': 2})

    # 启动进程执行任务
    coding_process.start()
    music_process.start()
